#coding=utf-8
from selenium import webdriver
from time import sleep
import time,datetime
import requests,json,urllib
from bs4 import BeautifulSoup
import bs4
import re
import random
import op_login

def download_users(url):
    # 引用运营系统登录函数op_login
    s = op_login.login(url)[1]
    login_status = op_login.login(url)[0]
    cookies = op_login.login(url)[2]
    headers = op_login.login(url)[3]
    if login_status == '0':
        print u"登录成功"

        for page in range(6471,7532,1):
            try:
                search_data = {'searchType': 'username', 'userSearchType': '10', 'page': page}
                search = s.get('http://op.' + url + '/user/menuUserList/', params=search_data, cookies=cookies, headers=headers,verify=False)
                #print search.text
                for i in range(0,106,11):
                    soup = BeautifulSoup(search.text, 'html.parser')
                    user_id = soup.find_all('td')[i].contents[0]
                    phone = soup.find_all('td')[i+4].contents[0]
                    status = soup.find_all('td')[i+7].contents[0]
                    if status == u'是':
                        user_information = s.get('http://op.' + url + '/user/DetailsVestMenuUserList/?userId=' + user_id,cookies=cookies, headers=headers,verify=False)
                        soup_information = BeautifulSoup(user_information.text, 'html.parser')
                        username = soup_information.find_all('li')[11].contents[0]
                        user_idcard = soup_information.find_all('li')[17].contents[0]
                        user_totalmoney = soup_information.find_all('li')[19].contents[0]
                        print user_id,phone,username,user_idcard,user_totalmoney
                        #sleep_time = random.random(0,5)
                        #time.sleep(sleep_time)
                        #print user_id,phone,status
            except:
                print u'异常'



    else:
        print u"登录失败"



if __name__ == '__main__':
    download_users('yipaiwang.com')